export class ApiKeyManager {
    constructor() {
        this.lastValidatedValue = ""
    }
    async validateApiKey(e) {
        try {
            return 401 !== (await fetch("https://api.deepseek.com/chat/completions", {
                method: "POST",
                headers: {
                    "Content-Type": "application/json",
                    Authorization: `Bearer ${e}`
                },
                body: JSON.stringify({
                    model: "deepseek-chat",
                    messages: [{
                        role: "system",
                        content: "You are a helpful assistant."
                    }, {
                        role: "user",
                        content: "Hello!"
                    }],
                    stream: !1
                })
            })).status
        } catch {
            return !1
        }
    }
    async saveApiKey(e) {
        return new Promise((t => {
            chrome.storage.sync.set({
                apiKey: e
            }, (() => {
                this.lastValidatedValue = e, t()
            }))
        }))
    }
    async getApiKey() {
        return new Promise((e => {
            chrome.storage.sync.get(["apiKey"], (t => {
                e(t.apiKey || "")
            }))
        }))
    }
}